package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class JDBCDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        // 加载数据库驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 创建数据库连接对象
        Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root"
        );
        // 创建SQL语句执行对象
        Statement statement = conn.createStatement();
        Scanner scanner = new Scanner(System.in);
        String username = scanner.nextLine();
        String sql = "delete from userinfo where username = " + "'" + username + "'";
        if (statement.executeUpdate(sql) > 0) {
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }
}
